/*
 * LevelSeleneseTest is unique in that it simulates a new player playing through all 5 levels.
 * To run this test successfully, you will need to reset the values of FurthestLevelPlayed and
 * AccumScore back to 1 and 0, respectively, for the player "Test".
 * 
 * IMPORTANT: This test will NOT run successfully if you do not reset the values of the variables stated above for username "Test" in the Player table of the database!
 */
package SeleniumTest;

import com.thoughtworks.selenium.SeleneseTestCase;
import java.util.regex.Pattern;

/**
 *
 * @author User
 */
public class LevelSeleneseTest extends SeleneseTestCase {

    @Override
	public void setUp() throws Exception {
            super.setUp("http://localhost:8080/","*firefox");
            selenium.setSpeed("2000"); //increase this for tests performed on slower connections
	}


        //tests that User can advance to harder levels once found the goal of the current level & scores will be rewarded
            public void testFirstLevel() throws Exception {
		selenium.open("/GooWhere/");

                //login with user class
		selenium.type("username", "Test"); // change the FurthestPlayedLevel back to 1 for this username each time this test is run
		selenium.type("password", "test");
		selenium.click("btn_login2");
		selenium.waitForPageToLoad("30000");

                //this simulates playing through first level
		selenium.click("go_north_west");
		selenium.click("trans_train_data_fourth");
                selenium.click("go_west");
		selenium.click("info_ok_button");
		selenium.click("go_north_west");
                selenium.click("go_north_west");
		selenium.click("trans_taxi_data_third");
		selenium.click("go_south_west");
		selenium.click("trans_taxi_data_third");
		selenium.click("go_south");
                selenium.click("go_south");
		selenium.click("trans_window_walk");

                //verify that user has received alert of level completion
		verifyTrue(selenium.isTextPresent("Congratulations, you have passed this level!"));
		selenium.click("message_win_exit");
                
                //log out user
                selenium.click("//img[@id='menu_game_logout']");
		selenium.click("ok_button");
		selenium.waitForPageToLoad("30000");

                //login a second time with user
		selenium.type("username", "Test");
		selenium.type("password", "test");
		selenium.click("btn_login2");
		selenium.waitForPageToLoad("30000");
                selenium.click("go_east");
		selenium.click("trans_window_cancel");
                
                //verify the user now starts at level 2 instead of 1
                verifyTrue(selenium.isTextPresent("LEVEL 2"));

            }

            public void testSecondLevel() throws Exception {
                selenium.open("/GooWhere/");

                //login with user class
		selenium.type("username", "Test"); // change the FurthestPlayedLevel back to 1 for this username each time this test is run
		selenium.type("password", "test");
		selenium.click("btn_login2");
		selenium.waitForPageToLoad("30000");

                //this simulates playing through the second level, and checks that the user successfully completes it
                selenium.click("go_east");
		selenium.click("trans_bus_data_fourth");
                selenium.click("go_east");
                selenium.click("go_east");
		selenium.click("trans_bus_data_third");
                selenium.click("go_north_east");
		selenium.click("trans_window_bus");
		selenium.click("go_west");
		selenium.click("trans_window_walk");
		verifyTrue(selenium.isTextPresent("Congratulations, you have passed this level!"));
		selenium.click("message_win_exit");
		selenium.click("level_window_data");
		verifyTrue(selenium.isTextPresent("LEVEL 3"));
		selenium.click("//img[@id='menu_game_logout']");
		selenium.click("ok_button");
		selenium.waitForPageToLoad("30000");
		selenium.type("username", "Test");
		selenium.type("password", "test");
		selenium.click("btn_login2");
		selenium.waitForPageToLoad("30000");
		selenium.click("level_window_data");
		verifyTrue(selenium.isTextPresent("LEVEL 3"));
            }

            public void testThirdLevel() throws Exception {
                selenium.open("/GooWhere/");

                //login with user class
		selenium.type("username", "Test"); // change the FurthestPlayedLevel back to 1 for this username each time this test is run
		selenium.type("password", "test");
		selenium.click("btn_login2");
		selenium.waitForPageToLoad("30000");

                //this simulates playing through the third level, and checks that the user successfully completes it
                selenium.click("go_north");
		selenium.click("go_north");
		selenium.click("trans_window_bus");
                selenium.click("go_north_west");
		selenium.click("go_north_west");
		selenium.click("trans_window_bus");
		selenium.click("go_north_east");
		selenium.click("go_north_east");
		selenium.click("trans_window_bus");
                selenium.click("go_north_east");
		selenium.click("go_north_east");
		selenium.click("trans_window_bus");
		selenium.click("go_east");
		selenium.click("go_east");
		selenium.click("//div[@id='loading_window_bg']/table");
		selenium.click("trans_walk_data_third");
		selenium.click("go_east");
                selenium.click("go_east");
		selenium.click("//div[@id='loading_window_bg']/table");
		selenium.click("trans_bus_data_third");
		selenium.click("go_north");
		selenium.click("go_north");
		selenium.click("trans_walk_data_fourth");
		verifyTrue(selenium.isTextPresent("Congratulations, you have passed this level!"));
		selenium.click("message_win_exit");
		verifyTrue(selenium.isTextPresent("LEVEL 4"));
		selenium.click("//img[@id='menu_game_logout']");
		selenium.click("ok_button");
		selenium.waitForPageToLoad("30000");
		selenium.type("username", "Test");
		selenium.type("password", "test");
		selenium.click("btn_login2");
		selenium.waitForPageToLoad("30000");
		verifyTrue(selenium.isTextPresent("LEVEL 4"));

           

	}

        //this simulates playing through the fourth level, and checks that the user successfully completes it
        public void testFourthLevel() throws Exception {

                selenium.open("/GooWhere/");

                //login with user class
		selenium.type("username", "Test"); // change the FurthestPlayedLevel back to 1 for this username each time this test is run
		selenium.type("password", "test");
		selenium.click("btn_login2");
		selenium.waitForPageToLoad("30000");

                //play through level 4
		selenium.click("go_north");
                selenium.click("go_north");
		selenium.click("trans_window_bus");
		selenium.click("go_north_east");
		selenium.click("go_north_east");
		selenium.click("trans_window_bus");
		selenium.click("go_north_west");
                selenium.click("go_north_west");
		selenium.click("trans_window_bus");
		selenium.click("go_north");
                selenium.click("go_north");
		selenium.click("info_ok_button");
		selenium.click("go_north_west");
		selenium.click("go_north_west");
                selenium.click("go_north_west");
		selenium.click("trans_bus_data_fourth");
		selenium.click("go_north");
                selenium.click("go_north");
		selenium.click("trans_window_bus");
		selenium.click("go_north_east");
                selenium.click("go_north_east");
		selenium.click("trans_window_bus");
		selenium.click("go_north_east");
                selenium.click("go_north_east");
		selenium.click("trans_window_walk");
		verifyTrue(selenium.isTextPresent("Congratulations, you have passed this level!"));
		selenium.click("message_win_exit");
		verifyTrue(selenium.isTextPresent("LEVEL 5"));
		selenium.click("//img[@id='menu_game_logout']");
		selenium.click("ok_button");
		selenium.waitForPageToLoad("30000");
		selenium.type("username", "Test");
		selenium.type("password", "test");
		selenium.click("btn_login2");
		selenium.waitForPageToLoad("30000");
		verifyTrue(selenium.isTextPresent("LEVEL 5"));


        }

        //this simulates playing through the fifth level, and checks that the user successfully completes it
        public void testFifthLevel() throws Exception {
               selenium.open("/GooWhere/");

                //login with user class
		selenium.type("username", "Test"); // change the FurthestPlayedLevel back to 1 for this username each time this test is run
		selenium.type("password", "test");
		selenium.click("btn_login2");
		selenium.waitForPageToLoad("30000");

                //play through level 5
                selenium.click("go_east");
                selenium.click("go_east");
		selenium.click("trans_bus_data_third");
		selenium.click("go_north_east");
		selenium.click("go_north_east");
		selenium.click("trans_bus_data_fourth");
		selenium.click("go_north");
                selenium.click("go_north");
		selenium.click("trans_window_bus");
		selenium.click("go_north_west");
                selenium.click("go_north_west");
		selenium.click("info_ok_button");
		selenium.click("go_north_east");
                selenium.click("go_north_east");
		selenium.click("trans_window_bus");
		selenium.click("go_north_west");
		selenium.click("go_north_west");
		selenium.click("trans_window_bus");
		selenium.click("go_north_west");
                selenium.click("go_north_west");
		selenium.click("trans_window_bus");
		selenium.click("go_north");
		selenium.click("go_north");
		selenium.click("trans_window_bus");
		selenium.click("go_north_east");
                selenium.click("go_north_east");
		selenium.click("trans_window_bus");
		verifyTrue(selenium.isTextPresent("Congratulations, you have passed this level!")); //keep in mind that no level 6 exists at this time

        }
 
}
